package crp.core.course.domain.repositories;

import com.qwlabs.lang.C2;
import com.qwlabs.panache.Where;
import crp.core.course.domain.models.CourseFacultyEntity;
import crp.core.course.domain.models.CourseFacultyRole;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;

import javax.enterprise.context.ApplicationScoped;
import java.util.Set;
import java.util.stream.Stream;

@ApplicationScoped
public class CourseFacultyRepository implements PanacheRepositoryBase<CourseFacultyEntity, String> {
    public Stream<CourseFacultyEntity> findByCourseIds(Set<String> courseIds,
                                                       Set<CourseFacultyRole> roles) {
        if (C2.isEmpty(courseIds)) {
            return Stream.empty();
        }
        Where where = Where.create().and("course.id in (:courseIds)", "courseIds", courseIds);
        if (C2.isNotEmpty(roles)) {
            where.and("role in (:roles)", "roles", roles);
        }
        return find(where.get(), where.getParameters()).stream();
    }
}
